
var offsetfromcursorX = 12;
var offsetfromcursorY = 10;
var offsetdivfrompointerX = 10;
var offsetdivfrompointerY = 14;

document.write('<div id="dhtmltooltip"></div>');
document.write('<img id="dhtmlpointertl" src="' + TooltipPoiterImagePath + 'tooltiparrowtl.gif">');
document.write('<img id="dhtmlpointertr" src="' + TooltipPoiterImagePath + 'tooltiparrowtr.gif">');
document.write('<img id="dhtmlpointerbl" src="' + TooltipPoiterImagePath + 'tooltiparrowbl.gif">');
document.write('<img id="dhtmlpointerbr" src="' + TooltipPoiterImagePath + 'tooltiparrowbr.gif">');

var ie = document.all;
var ns6 = document.getElementById && ! document.all;
var enabletip = false;

if (ie || ns6)
	var tipobj = document.all ? document.all["dhtmltooltip"] : document.getElementById ? document.getElementById("dhtmltooltip") : "";

var pointerobjtl = document.all ? document.all["dhtmlpointertl"] : document.getElementById ? document.getElementById("dhtmlpointertl") : "";
var pointerobjtr = document.all ? document.all["dhtmlpointertr"] : document.getElementById ? document.getElementById("dhtmlpointertr") : "";
var pointerobjbl = document.all ? document.all["dhtmlpointerbl"] : document.getElementById ? document.getElementById("dhtmlpointerbl") : "";
var pointerobjbr = document.all ? document.all["dhtmlpointerbr"] : document.getElementById ? document.getElementById("dhtmlpointerbr") : "";

function ietruebody() {
	return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function showtip(objTextID, thewidth, thecolor) {
	if (ns6 || ie) {
		var objText = document.all ? document.all[objTextID] : document.getElementById ? document.getElementById(objTextID) : "";
		if (typeof thewidth != "undefined")
			tipobj.style.width = thewidth + "px";
		if (typeof thecolor != "undefined" && thecolor != "")
			tipobj.style.backgroundColor = thecolor;
		tipobj.innerHTML = objText.innerHTML;
		tipobj.onmouseout = hidetip;
		enabletip = true;
		return false;
	}
}

function positiontip(e) {
	if (enabletip) {
		var rightpos = false;
		var bottompos = false;
				
		var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
		var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
		
		var winwidth = ie && ! window.opera ? ietruebody().clientWidth : window.innerWidth - 20;
		var winheight = ie && ! window.opera ? ietruebody().clientHeight : window.innerHeight - 20;

		var rightedge = ie && ! window.opera ? winwidth - event.clientX - offsetfromcursorX : winwidth - e.clientX - offsetfromcursorX;
		var bottomedge = ie && ! window.opera ? winheight - event.clientY - offsetfromcursorY : winheight - e.clientY - offsetfromcursorY;

		var leftedge = (offsetfromcursorX < 0) ? offsetfromcursorX * (- 1) : - 1000;

		if (rightedge < tipobj.offsetWidth) {
			tipobj.style.left = curX - tipobj.offsetWidth + "px";
			rightpos = true;
			//pointerobjr.style.left = curX - offsetfromcursorX - offsetdivfrompointerX + "px";
		}
		else if (curX < leftedge)
			tipobj.style.left = "5px";
		else {
			tipobj.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + "px";
			//pointerobjl.style.left = curX + offsetfromcursorX + "px";
		}

		if ((bottomedge < tipobj.offsetHeight) && (curY > tipobj.offsetHeight)) {
			tipobj.style.top = curY - tipobj.offsetHeight - offsetfromcursorY + "px";		//tipobj.style.top = curY + offsetfromcursorY + "px";
			bottompos = true;
		}
		else {
			tipobj.style.top = curY + offsetfromcursorY + offsetdivfrompointerY + "px";
			//pointerobjl.style.top = curY + offsetfromcursorY + "px";
			//pointerobjr.style.top = curY + offsetfromcursorY + "px";
		}
		
		if (tipobj.offsetWidth < 30) tipobj.style.width = 30;
		tipobj.style.visibility = "visible";

		if (!rightpos){
			if (!bottompos){
				pointerobjtl.style.visibility = "hidden";
				pointerobjtr.style.visibility = "visible";
				pointerobjbl.style.visibility = "hidden";
				pointerobjbr.style.visibility = "hidden";
				
				pointerobjtr.style.left = curX + offsetfromcursorX + "px";
				pointerobjtr.style.top = curY + offsetfromcursorY + "px";
			}else{
				pointerobjtl.style.visibility = "hidden";
				pointerobjtr.style.visibility = "hidden";
				pointerobjbl.style.visibility = "hidden";
				pointerobjbr.style.visibility = "visible";
				
				pointerobjbr.style.left = curX + offsetfromcursorX + "px";
				pointerobjbr.style.top = curY - offsetfromcursorY  - 1 + "px";
			}			
		}else{
			if (!bottompos){
				pointerobjtl.style.visibility = "visible";
				pointerobjtr.style.visibility = "hidden";
				pointerobjbl.style.visibility = "hidden";
				pointerobjbr.style.visibility = "hidden";
				
				pointerobjtl.style.left = curX - offsetfromcursorX - offsetdivfrompointerX + "px";
				pointerobjtl.style.top = curY + offsetfromcursorY + "px";
			}else{
				pointerobjtl.style.visibility = "hidden";
				pointerobjtr.style.visibility = "hidden";
				pointerobjbl.style.visibility = "visible";
				pointerobjbr.style.visibility = "hidden";
				
				pointerobjbl.style.left = curX - offsetfromcursorX - offsetdivfrompointerX + "px";
				pointerobjbl.style.top = curY - offsetfromcursorY - 1 + "px";
			}			
		}
	}
}

function hidetip() {
	if (ns6 || ie) {
		enabletip = false;
		tipobj.style.visibility = "hidden";
		pointerobjtl.style.visibility = "hidden";
		pointerobjtr.style.visibility = "hidden";
		pointerobjbl.style.visibility = "hidden";
		pointerobjbr.style.visibility = "hidden";		
		tipobj.style.left = "-1000px";
		tipobj.style.backgroundColor = '';
		tipobj.style.width = '';
	}
}

if ( typeof window.addEventListener != "undefined" )
document.addEventListener( "mousemove", positiontip, false );
else if ( typeof window.attachEvent != "undefined" )
document.attachEvent( "onmousemove", positiontip );
else {
if ( document.onmousemove != null ) {
var oldOnmousemove = document.onmousemove;
document.onmousemove = function ( e ) {
oldOnmousemove( e );
positiontip(e);
};
}
else
document.onmousemove = positiontip;
}